fix: add missing support for oneOf directive in schema printer #1727
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Add Missing Test and Support for
@oneOf
Directive in Schema PrinterSummary
This PR addresses missing test coverage and implementation gaps for the
@oneOf
directive in the schema printer. While PR #1715 implemented the core@oneOf
directive support, it was missing tests to ensure the directive is properly printed when schemas are serialized, and the underlying build cycle was not preserving the directive.This fix ensures full compatibility with the GraphQL.js reference implementation for schema printing and rebuilding.
Missing Test Coverage
testInputTypeWithOneOfDirective()
inSchemaPrinterTest.php
to verify@oneOf
directive printing for input types withisOneOf: true
testCorrectlyExtendInputObjectTypeWithOneOfDirective()
inBuildSchemaTest.php
to cover@oneOf
directive parsing from input object extensionsprintSchema-test.ts
Schema Printer Fix
printInputObject()
inSchemaPrinter.php
to check$type->isOneOf()
and append@oneOf
directive when trueBuild Schema Fix
makeInputObjectDef()
inASTDefinitionBuilder.php
to:@oneOf
directive from input object definition nodes usingValues::getDirectiveValues()
@oneOf
directive from extension nodes (previously uncovered code path)isOneOf
property correctly when buildingInputObjectType
instances@throws
annotations for PHPStan complianceRoot Cause
The issue occurred because:
SchemaPrinter::printInputObject()
was not checking theisOneOf
propertyASTDefinitionBuilder::makeInputObjectDef()
was not parsing the@oneOf
directive from AST nodesInputObjectType
→print
→build
→print
was not preserving the directiveTest Coverage
@oneOf
directive appears in printed schemaSchemaPrinter::doPrint()
→BuildSchema::build()
→SchemaPrinter::doPrint()
cycle@oneOf
directive parsing from both main definitions and extension nodesBreaking Changes
None. This is a bug fix that adds missing functionality without changing existing behavior.
Validation Results
Example Scenarios
Main Definition:
Extension Definition:
Both scenarios now properly preserve the
@oneOf
directive through the complete build cycle.